package server.startup;

import server.Valve;
import server.connector.http.HttpConnector;
import server.core.SimpleLoader;
import server.core.SimpleWrapper;
import server.valves.ClientIPLoggerValve;
import server.valves.HeaderLoggerValve;

public class BootStrap1 {
    public static void main(String[] args) {
        HttpConnector httpConnector = new HttpConnector();

        //简单的类加载器
        SimpleLoader loader = new SimpleLoader();
        //阀1
        Valve valve1 = new HeaderLoggerValve();
        //阀2
        Valve valve2 = new ClientIPLoggerValve();
        //一个wrapper包装一个Servlet类
        SimpleWrapper wrapper = new SimpleWrapper();
        wrapper.setServletClass("ModernServlet");
        wrapper.setLoader(loader);
        wrapper.addValve(valve1);
        wrapper.addValve(valve2);
        httpConnector.setContainer(wrapper);

        try {
            //连接器初始化,创建ServerSocket
            httpConnector.initialize();
            //连接器创建好初始的处理器数后启动自己的线程
            httpConnector.start();

            System.in.read();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
